<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<style>
    a {
        text-decoration: none;
        color: #666666;
    }

    .list {
        margin: 0 auto;
        width: 550px;
        list-style: none;
    }

    .list .list-item {
        text-align: center;
        line-height: 40px;
        float: left;
        width: 110px;
        height: 40px;
        background-color: rgba(0, 204, 255, 0.726);
        position: relative;
    }

    .list .list-item.on {
        background-color: goldenrod;
    }

    .lb {
        display: none;
        height: 160px;
        list-style: none;
        position: absolute;
        top: 40px;
        left: -25px;


    }

    .lb .lb-item {
        width: 80px;
        height: 40px;
        background-color: palevioletred;
        text-align: center;
        line-height: 40px;

    }
</style>

<body>
    <ul class="list">
        <li class="list-item">
            <a href="#">首页</a>
            <ul class="lb">
                <li class="lb-item">1</li>
                <li class="lb-item">2</li>
                <li class="lb-item">3</li>
                <li class="lb-item">4</li>
            </ul>
        </li>
        <li class="list-item">
            <a href="#">介绍</a>
        </li>
        <li class="list-item">
            <a href="#">关于我们</a>
            <ul class="lb">
                <li class="lb-item">1</li>
                <li class="lb-item">2</li>
                <li class="lb-item">3</li>
                <li class="lb-item">4</li>
            </ul>
        </li>
        <li class="list-item">
            <a href="#">新闻</a>
        </li>
        <li class="list-item">
            <a href="#">详情</a>
            <ul class="lb">
                <li class="lb-item">1</li>
                <li class="lb-item">2</li>
                <li class="lb-item">3</li>
                <li class="lb-item">4</li>
            </ul>
        </li>
    </ul>
</body>
<script>
    let lis = document.querySelectorAll(".list-item")
    lis.forEach(function (li, i) {
        li.addEventListener("mouseenter", function () {

            li.classList.add("on")
            if (li.children.length === 2) {
                li.children[1].style.display = "block"
            }
        })
        li.addEventListener("mouseleave", function () {

            li.classList.remove("on")
            if (li.children.length === 2) {
                li.children[1].style.display = "none"
            }
        })
    })
</script>

</html>